# 数据库连接工具包
from pymysql import Connection

def getCon():
    con = Connection(
        host='localhost',
        port=3306,
        user='root',
        password='123456',
        database='cre_db',
        autocommit=True,
        charset='utf8'
    )
    return con
def closeCon(con:Connection):
    if con:
        con.close()

if __name__ == '__main__':
    con = None
    try:
        con = getCon()
        cursor=con.cursor()
        cursor.execute('select * from book')
        print(cursor.fetchall())
    except Exception as e:
        print(e)
    finally:
        closeCon(con)